<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增/修改经销商星级</title>
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/ligerUI/skins/Aqua/css/ligerui-all.css"/>
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/ligerUI/skins/sqBlue/css/all.css">
    <link rel="stylesheet" type="text/css" href="<%=path %>/resource/lib/ligerUI/skins/sqBlue/css/sq-sj.css">
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .form_view {
            padding: 10px 0;
        }
    </style>
</head>
<script type="text/javascript">
    var id = '${id}'
    var opTypCd = '${opTypCd}'
    var flag = false;
    var parseFileRecId = '${parseFileRecId }';
    var _verNum = '${verNum}';
    var _opObjTyp = '${opObjTyp}';
    var _dataTypCd = '${dataTypCd}';
    var _opDataTabNm = '${opDataTabNm}';

    $(function () {
        if (id) {
            initData();
        } else {
            $("#verNum").val(_verNum);
        }
        $("#formSet1").ligerForm({
            validate: true
        });
        $("#formSet1").ligerForm();

        disableFiled(opTypCd);

        $("#splNm").ligerComboBox({
            width: 200,
            slide: false,
            selectBoxWidth: 700,
            selectBoxHeight: 450,
            valueField: 'id',
            textField: 'splNm',
            condition: {fields: [{name: 'splNm', label: '经销商', width: 90, type: 'text'}]},
            grid: getGridOptions(true),
            conditionSearchClick: function (e) {
                //debugger
                if (e.rules[0] && e.rules[0].value) {
                    e.grid.set('parms', {splNm: e.rules[0].value});
                } else {
                    e.grid.set('parms', '');
                }
                e.grid.reload();

            },
            onSelected: function (splId) {
                console.log('选择的是' + splId);
                $('#splId').val(splId);

                $('#dataId').val(splId);
                $('#dataNm').val($('#splNm').val());
            }
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $('#splId').val('');
            $('#splNm').val('');
            $('#dataId').val('');
            $('#dataNm').val('');
        });

    })

    function initData() {
        var _url = '<%=path%>/splrate/splraterelinfo/getById.do';
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: {id: id},
            url: _url,
            success: function (msg) {
                if (msg.success == 1) {
                    setData(msg.data);//设置数据
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function setData(data) {
        $("#dataId").val(data.dataId);
        $("#dataNm").val(data.dataNm);
        $("#rateScore").val(data.rateScore);
        $("#starLevel").val(data.starLevel);
        $("#verNum").val(data.verNum);
        $("#rateRem").val(data.rateRem);
        $("#rateLvl").val(data.rateLvl);

        var form = liger.get("formSet1");
        form.setData({
            starLevel: data.starLevel,
            dataSource: data.dataSource
        });

    }

    function disableFiled(op) {
        if (liger.get("dataId")) {
            liger.get("dataId").setDisabled(true);
        }
        if (liger.get("dataNm")) {
            liger.get("dataNm").setDisabled(true);
        }
        if (liger.get("verNum")) {
            liger.get("verNum").setDisabled(true);
        }
        if (liger.get("dataSource")) {
            liger.get("dataSource").setDisabled(true);
        }
        if (!opTypCd || opTypCd == 'DETAIL') {
            if (liger.get("dataSource")) {
                liger.get("dataSource").setDisabled(true);
            }
            if (liger.get("starLevel")) {
                liger.get("starLevel").setDisabled(true);
            }
            if (liger.get("rateScore")) {
                liger.get("rateScore").setDisabled(true);
            }
        }
    }

    function getGridOptions(checkbox) {
        var options = {
            columns: [
                {display: '供应商ID', name: 'id', align: 'left', width: 120, minWidth: 60},
                {display: '供应商名称', name: 'splNm', minWidth: 120, width: 100},
                {display: '审核状态', name: 'audStsCdNm', minWidth: 50, enabledSort: false},
                {
                    display: '是否黑名单', minWidth: 120, enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (!rowdata.isBlackList || rowdata.isBlackList == 0) {
                            return "否";
                        }
                        return "是";
                    }
                }
                /* { display: '联系名', name: 'ContactName', minWidth: 140, width: 100 },
                 { display: '电话', name: 'Phone', width: 100 },
                 { display: '城市', name: 'City', width: 100 },
                 { display: '国家', name: 'Country', width: 100 }*/
            ], switchPageSizeApplyComboBox: false,
            url: '<%=path%>/product/splInfo/initList.do',
            pageSize: 10,
            root: 'rows',
            record: 'total',
            width: '100%',
            height: '100%'
            //checkbox: checkbox
        };
        return options;
    }

    var condition = {fields: [{name: 'splNm', label: '商家名称:', width: 180, type: 'text'}]};


    //定义父级调用事件
    frameElement.dialog.onOk = function () {
        flag = true;
        save();
    }

    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }

    function save() {
        var form = liger.get("formSet1");
        if (!form.valid()) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
        var _id = $("#sId").val();
        data['parseFileRecId'] = parseFileRecId;
        data['dataTypCd'] = _dataTypCd;
        data['opObjTyp'] = _opObjTyp;
        data['opDataTabNm'] = _opDataTabNm;
        console.log(_id + ",data:" + JSON.stringify(data));
        var url = '';
        if (_id) {
            url = '<%=path%>/splrate/splraterelinfo/modify.do';
            data["id"] = _id;
        } else {
            url = '<%=path%>/splrate/splraterelinfo/add.do';
        }
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $("#sId").val(msg.data);
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    if (flag) {
                        parent.callback();
                        frameElement.dialog.close();
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
</script>
<body class="iframeBody">
<div class="Wrapper">
    <c:if test="${not empty opTypCd and opTypCd == 'ADD'}">
        <div class="form_view">
            <form id="searchBar">
                <div class="fieldset1 clearFix">
                    <div class="sqPanel_body">
                        <div class="fieldBox">
                            <div class="label">经销商名称</div>
                            <div class="field">
                                <input name="splNm" id="splNm" type="text"/>
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="field">
                                <input name="splId" id="splId" type="hidden"/>
                            </div>
                        </div>
                        <div class="fieldBox btnsBox btm">
                            <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </c:if>
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="基本信息" lselected="true">
            <form id="formSet1">
                <div class="fieldset1 tabel_col clearFix">

                    <div class="caption">
                        <span class="title">基本信息</span>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">经销商ID</div>
                        <div class="field">
                            <input type="text" id="dataId" name="dataId" class="ui-textbox" validate="{required:true}"/>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">经销商名称</div>
                        <div class="field">
                            <input type="text" id="dataNm" name="dataNm" class="ui-textbox" validate="{required:true}"/>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">经销商评分</div>
                        <div class="field">
                            <input name="rateScore" id="rateScore" type="text"
                                   class="ui-textbox" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">经销商星级</div>
                        <div class="field">
                            <select name="starLevel" id="starLevel" data-value=" "
                                    validate="{required:true,select:true}">
                                <option value=" " seleted>请选择</option>
                                <c:forEach items="${starLvlList }" var="kv">
                                    <option value="${kv.key }">${kv.value }</option>
                                </c:forEach>
                            </select>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">经销商评级</div>
                        <div class="field">
                            <input name="rateLvl" id="rateLvl" type="text"
                                   class="ui-textbox">
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">评级数据来源</div>
                        <div class="field">
                            <c:choose>
                                <c:when test="${not empty opTypCd and opTypCd == 'ADD'}">
                                    <select name="dataSource" id="dataSource" data-value=" "
                                            validate="{required:true,select:true}">
                                        <option value="ADDMANUAL" seleted>手动新增</option>
                                    </select>
                                    <span class="requiredSymbol">*</span>
                                </c:when>
                                <c:otherwise>
                                    <select name="dataSource" id="dataSource" data-value=" "
                                            validate="{required:true,select:true}">
                                        <option value="" seleted>请选择</option>
                                        <c:forEach items="${dataSourceList }" var="kv">
                                            <option value="${kv.key }">${kv.value }</option>
                                        </c:forEach>
                                    </select>
                                    <span class="requiredSymbol">*</span>
                                </c:otherwise>
                            </c:choose>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">版本号</div>
                        <div class="field">
                            <input name="verNum" id="verNum" type="text"
                                   class="ui-textbox" readonly="readonly">
                        </div>
                    </div>

                    <div class="fieldBox col_100">
                        <div class="label">备注</div>
                        <div class="field">
                            <input type="text" id="rateRem" name="rateRem" class="ui-textbox"/>
                        </div>
                    </div>
                    <input name="sId" id="sId" type="hidden" value="${id }">
                </div>
                <c:if test="${empty opTypCd or opTypCd == 'DETAIL'}">
                    <div class="btnsBox">
                        <span id="saveBtn1" onclick="save();" class="sq-button sq-button-round">保存</span>
                    </div>
                </c:if>
            </form>
        </div>
    </div>
</div>

</body>
</html>